package leetcode;

import java.util.Scanner;

public class code11 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int[] height = new int[i];
        for (int i1 = 0; i1 < i; i1++) {
            height[i1] = scanner.nextInt();
        }
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int left = 0;
        int right = height.length-1;
        int max = Integer.MIN_VALUE;
        while (right > left){
            int area = (right-left) * Math.min(height[right],height[left]);
            max = Math.max(max,area);
            if (height[right] >= height[left]){
                left++;
            }else {
                right--;
            }
        }
        return max;
    }
}
